package io.gitee.chearnee.fw.common.component.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * * RequestParam PathVariable 的反序列化 * @see RequestParam * @see PathVariable
 *
 * @author cn
 * @version 1.0
 * @description
 * @date 2022/5/10 15:09
 */
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {

  public LocalDateTime convert(String source) {
    if (!StringUtils.hasText(source)) {
      return null;
    }
    return LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(source)), ZoneOffset.ofHours(8));
  }
}
